package com.ck.ck_back.controller;

import com.ck.ck_back.pojo.Result;
import com.ck.ck_back.service.focusservice;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/focus")
@RestController
public class FocusController {
    @Resource
    private focusservice focusserviceimpl;

//    获取数量，做到只能有一条
    @PostMapping("/get_focus_num")
    public Object getfocus(String master_id,String post_id){
        int result = focusserviceimpl.getfocus_num(master_id,post_id);
        if (result ==1 ||result == 0){
            return Result.success(result);
        }else if (result == 404){return Result.failure("参数错误");}
        else {{return Result.failure("失败");}}
    }

//    获取内容
    @PostMapping("/getfocus")
    public Object getfocus(String master_id){
        return Result.success(focusserviceimpl.getfocus(master_id));
    }

//    增加关注
    @PostMapping("/add")
    public Object add(String master_id, String post_id){
        int result = focusserviceimpl.add(master_id, post_id);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("插入错误");
        }else if (result == 3){
            return Result.failure("已有此数据");
        }else {return Result.failure("参数错误");}
    }

    @PostMapping("/update")
    public Object update(String master_id, String post_id){
        int result = focusserviceimpl.update(master_id, post_id);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("更新错误");
        }else if (result == 3){
            return Result.failure("无此数据");
        }else {return Result.failure("参数错误");}
    }

    @PostMapping("/get_state")
    public Object get_state (String master_id, String post_id){
        int result = focusserviceimpl.get_state(master_id, post_id);
        if (result==0 || result==1){
            return Result.success(result);
        }else if (result == 404){return Result.failure("参数错误");
        }else {return Result.failure("错误");}
    }

    @PostMapping("/delete")
    public Object delete(int focusId){
        int result = focusserviceimpl.delectfocus(focusId);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("删除错误");
        }else if (result == 3){
            return Result.failure("无此数据");
        }else {return Result.failure("参数错误");}
    }
}
